/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.sqlexpr;

/**
 *
 * @author trekan
 */
public class OracleVisitor extends SqlVisitor {
    
    @Override
    public void visit(Select select) throws SyntaxException {
        
        sb.append("select ").append(select.select).append(" from ").append(select.from);
        if (select.startWith != null) {
            sb.append(" start with ");
            select.startWith.accept(this);
        }
        if (select.connectBy != null) {
            sb.append(" connect by ");
            select.connectBy.accept(this);
        }
        if (select.where != null) {
            whereStarted = true;
            select.where.accept(this);
        }
        if (select.orderBy != null) {
            sb.append(" order by ").append(select.orderBy);
        }
        if (select.paging != null) {
            select.paging.accept(this);
        }
    }

    @Override
    public void visit(Paging paging) {
        sb.insert(0, "select * from (select pageddata.*, rownum as rn from (");
        sb.append(") pageddata) where rn >= ").append(paging.offset);
        sb.append(" and rownum <= ").append(paging.limit);
        
    }

}
